package com.inossem.warehousestorage_inossem.utils;

import android.content.Context;

import com.inossem.warehousestorage_inossem.bean.analysis.AnalysisWorkStatisticsGetPersonBean;
import com.inossem.warehousestorage_inossem.bean.analysis.AnalysisWorkStatisticsIndexBean;
import com.inossem.warehousestorage_inossem.bean.analysis.AnalysisWorkStatisticsRequestBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leij on 2018/1/10.
 */

public class AnalysisUtils {

    public static List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean> getFactoryList(AnalysisWorkStatisticsIndexBean bean, String blockValue) {
        List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean> result = new ArrayList<>();
        result.add(getFirstFactory());
        List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean> blockList = bean.getData().getBlockList();
        for (int i = 0; i < blockList.size(); i++) {
            AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean blockItem = blockList.get(i);
            if (blockItem.getBlockValue().equals(blockValue)) {
                result.addAll(blockItem.getFactoryList());
                break;
            }
        }
        return result;
    }

    public static AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean getFirstFactory() {
        AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean result = new AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean();
        result.setFactoryName("全部工厂");
        result.setFactoryValue("");
        return result;
    }

    public static List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean.InventoryAddressListBean> getInventoryAddressList(AnalysisWorkStatisticsIndexBean bean, String blockValue, String factoryValue) {
        List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean.InventoryAddressListBean> result = new ArrayList<>();
        result.add(getFirstInventoryAddress());
        List<AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean> factoryList = getFactoryList(bean, blockValue);
        for (int i = 0; i < factoryList.size(); i++) {
            AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean factoryItem = factoryList.get(i);
            if (factoryItem.getFactoryValue().equals(factoryValue)) {
                result.addAll(factoryItem.getInventoryAddressList());
                break;
            }
        }
        return result;
    }

    public static AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean.InventoryAddressListBean getFirstInventoryAddress() {
        AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean.InventoryAddressListBean result = new AnalysisWorkStatisticsIndexBean.DataBean.BlockListBean.FactoryListBean.InventoryAddressListBean();
        result.setInventoryAddressName("全部库存地点");
        result.setInventoryAddressValue("");
        return result;
    }

    public static List<AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean> getPersonList(List<AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean> personList) {
        List<AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean> result = new ArrayList<>();
        result.add(getFirstPerson());
        result.addAll(personList);
        return result;
    }

    public static AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean getFirstPerson() {
        AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean result = new AnalysisWorkStatisticsGetPersonBean.DataBean.PersonListBean();
        result.setName("全部人员");
        result.setId("");
        return result;
    }

    //拼验收入库对象
    public static AnalysisWorkStatisticsRequestBean getAnalysisWorkStatisticsRequestBean(Context context, String blockValue, String factoryValue, String inventoryAddressValue, String id, String beginTime, String endTime) {
        AnalysisWorkStatisticsRequestBean result = new AnalysisWorkStatisticsRequestBean();
        result.setBlockValue(blockValue);
        result.setFactoryValue(factoryValue);
        result.setInventoryAddressValue(inventoryAddressValue);
        result.setId(id);
        result.setBeginTime(beginTime);
        result.setEndTime(endTime);
        return result;
    }
}
